package com.xilihui.xlh.business.dialogs;

import android.app.Activity;
import android.app.Dialog;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.xilihui.xlh.R;
import com.xilihui.xlh.core.util.ToastUtil;

import org.feezu.liuli.timeselector.Utils.TextUtil;

/**
 * Created by Administrator on 2018/9/27.
 */

public class InputDialog {
    
    Dialog dialog;
    Activity activity;
    EditText et_input;
    TextView tv_cancel;
    TextView tv_sure;
    private OnInputListener listener;

    public InputDialog(Activity activity){
        this.activity = activity;
        dialog = new Dialog(activity, R.style.Dialog);
        dialog.setContentView(R.layout.dialog_input);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.getWindow().setGravity(Gravity.CENTER);
    
        initView();
    }
    
    public void initView(){
        et_input = (EditText)dialog.findViewById(R.id.et_input);
        tv_cancel = (TextView)dialog.findViewById(R.id.tv_cancel);
        tv_sure = (TextView)dialog.findViewById(R.id.tv_sure);

        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        
        tv_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(TextUtil.isEmpty(et_input.getText().toString())){
                    ToastUtil.toastShortNegative("请输入备注");
                    return;
                }
                listener.beizhu(et_input.getText().toString());
                dialog.dismiss();
            }
        });

    }
    
    
    public void show(){
        dialog.show();
    }
    
    public void dismiss(){
        dialog.dismiss();
    }
    
    public void setOnInputListener(OnInputListener listener){
        this.listener = listener;
    }
    
    public interface OnInputListener{
        void beizhu(String content);
    }
    
}
